// 一个工具函数的 js 文件

// 一个判断数字是不是质数的函数
function isZhishu(num) {
  var flag = true
  for (var i = 2; i < num; i++) {
    if (num % i === 0) {
      flag = false
      break
    }
  }
  return flag
}

// 求两个数字的最大公约数
function gongYueShu(a, b) {
  var max = a
  var min = b
  if (b > a) {
    max = b
    min = a
  }

  var gys = 1
  for (var i = min; i >= 1; i--) {
    if (min % i === 0 && max % i === 0) {
      gys = i
      break
    }
  }

  return gys
}

// 求两个数字的最小公倍数
function gongBeishu(a, b) {
  var gbs = a * b / gongYueShu(a, b)

  return gbs
}

// 计算两个时间节点之间的时间差
function timeDiff(time1, time2) {
  var diff = Math.floor(Math.abs(time1.getTime() - time2.getTime()) / 1000)
  var day = Math.floor( diff / (60 * 60 * 24) )
  var hours = Math.floor( diff % (60 * 60 * 24) / (60 * 60) )
  var minutes = Math.floor( diff % (60 * 60) / 60 )
  var seconds = diff % 60
  var obj = {}
  obj.day = day
  obj.hours = hours
  obj.minutes = minutes
  obj.seconds = seconds
  return obj
}

// 求范围之间的随机数字
function randomNum(x, y) {
  var min = Math.min(x, y)
  var max = Math.max(x, y)

  var n = Math.floor(Math.random() * (max - min + 1) + min)

  return n
}

// 一个十六进制的随机颜色
function hexRandomColors(x,y){
    var max,minutes
    max = x > y ? x : y
    min = x < y ? x : y

    var c = parseInt(Math.random() * (max - min + 1) + min)
    if( c < 16){
      c = '0' + c.toString(16)
    }else{
      c = c.toString(16)
    }
    return c
}
